package com.ycd.gis.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ycd.common.annotation.Log;
import com.ycd.common.enums.BusinessType;
import com.ycd.gis.domain.GisApi;
import com.ycd.gis.service.IGisApiService;
import com.ycd.common.core.controller.BaseController;
import com.ycd.common.core.domain.AjaxResult;
import com.ycd.common.utils.poi.ExcelUtil;
import com.ycd.common.core.page.TableDataInfo;

/**
 * 系统接口Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@Controller
@RequestMapping("/gis/api")
public class GisApiController extends BaseController
{
    private String prefix = "gis/api";

    @Autowired
    private IGisApiService gisApiService;

    @RequiresPermissions("gis:api:view")
    @GetMapping()
    public String api()
    {
        return prefix + "/api";
    }

    /**
     * 查询系统接口列表
     */
    @RequiresPermissions("gis:api:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GisApi gisApi)
    {
        startPage();
        List<GisApi> list = gisApiService.selectGisApiList(gisApi);
        return getDataTable(list);
    }

    /**
     * 导出系统接口列表
     */
    @RequiresPermissions("gis:api:export")
    @Log(title = "系统接口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GisApi gisApi)
    {
        List<GisApi> list = gisApiService.selectGisApiList(gisApi);
        ExcelUtil<GisApi> util = new ExcelUtil<GisApi>(GisApi.class);
        return util.exportExcel(list, "系统接口数据");
    }

    /**
     * 新增系统接口
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统接口
     */
    @RequiresPermissions("gis:api:add")
    @Log(title = "系统接口", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GisApi gisApi)
    {
        return toAjax(gisApiService.insertGisApi(gisApi));
    }

    /**
     * 修改系统接口
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GisApi gisApi = gisApiService.selectGisApiById(id);
        mmap.put("gisApi", gisApi);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统接口
     */
    @RequiresPermissions("gis:api:edit")
    @Log(title = "系统接口", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GisApi gisApi)
    {
        return toAjax(gisApiService.updateGisApi(gisApi));
    }

    /**
     * 删除系统接口
     */
    @RequiresPermissions("gis:api:remove")
    @Log(title = "系统接口", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gisApiService.deleteGisApiByIds(ids));
    }
}
